using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace LocalizationTest
{
  public class AngleMeasurement : Measurement
  {
    private double angle;

    public AngleMeasurement()
    {
      this.angle = 0;
      this.sensor = null;
    }

    public AngleMeasurement(double angle, Sensor sensor)
    {
      this.angle = angle;
      this.sensor = sensor;
    }

    public double Angle
    {
      get { return angle; }
    }

    public double AngleInDegrees
    {
      get { return angle; }
    }

    public override double GetValueAsDouble()
    {
      return this.angle;
    }

    public override double GetDifference(Measurement other)
    {
      double toReturn = this.angle - ((AngleMeasurement)other).angle;
      if(toReturn < -Math.PI) toReturn += 2.0 * Math.PI;
      if (toReturn > Math.PI) toReturn -= 2.0 * Math.PI;
      return toReturn;
    }

    public override Measurement Parse(string str, Experiment experiment)
    {
      string[] parts = str.Split('/');
      Sensor sensor = experiment.GetSensorByString(parts[0]);
      double angle = double.Parse(parts[1]);
      return new AngleMeasurement(angle, sensor);
    }

    public override string ToString()
    {
      return (
        this.GetType().Name + "|" + 
        this.sensor.ToString() + "/" + 
        angle.ToString());
    }

  }
}
